package com.sqx.modules.pushMsgType.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.pushMsgType.entity.PushMsgType;
import com.sqx.modules.pushMsgType.service.PushMsgTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 工作提醒-用户端
 * @author wuChang
 * @since 2024-03-28
 */
@RestController
@Api(value = "工作提醒-用户端", tags = {"工作提醒-用户端"})
@RequestMapping("/app/pushMsgType/")
public class AppPushMsgTypeController {
    @Autowired
    private PushMsgTypeService pushMsgTypeService;

    /**
     * 新增或修改工作提醒
     *@param pushMsgType 工作提醒
     */
    @Login
    @ApiOperation("新增或修改工作提醒")
    @PostMapping(value = "savePushMsgType")
    public Result savePushMsgType(@RequestAttribute Long userId, PushMsgType pushMsgType) {
        pushMsgType.setUserId(userId);
        pushMsgType.setIsEnable(0);
        return pushMsgTypeService.savePushMsgType(pushMsgType);
    }

    /**
     * 获取工作提醒详情
     */
    @Login
    @ApiOperation("获取工作提醒详情")
    @GetMapping(value = "getPushMsgTypeByUser")
    public Result getPushMsgTypeById(@RequestAttribute Long userId) {
        return Result.success().put("data", pushMsgTypeService.getOne(new QueryWrapper<PushMsgType>().eq("user_id", userId)));
    }

    /**
     * 开启或关闭工作提醒
     */
    @Login
    @ApiOperation("开启或关闭工作提醒")
    @GetMapping(value = "updateEnable")
    public Result updateEnable(@RequestAttribute Long userId) {
        return pushMsgTypeService.updateEnable(userId);
    }

}